#include <stdio.h>

/*
 * 多个结束标志
 */

int func(int a)
{
    if (a)
        return a++;

    return 1/a;
}

void main()
{
    printf("%d\n", func(5));   // 5
}

#if 0
/*
 * intel
 */
0000000000001149 <func>:
    1149:	f3 0f 1e fa          	endbr64 
    114d:	55                   	push   %rbp					// rsp=rsp-8, (rsp)=rbp ===> subq $8,%rsp, movq %rbp,(%rsp)
    114e:	48 89 e5             	mov    %rsp,%rbp			// rbp=rsp
    1151:	89 7d fc             	mov    %edi,-0x4(%rbp)		// rbp-4 = edi
    1154:	83 7d fc 00          	cmpl   $0x0,-0x4(%rbp)		// if ((rbp-4 - 0) == 0)
    1158:	74 0b                	je     1165 <func+0x1c>		// 参数等于零跳转
    115a:	8b 45 fc             	mov    -0x4(%rbp),%eax		// eax = rbp-4
    115d:	8d 50 01             	lea    0x1(%rax),%edx		// edx = rax+1
    1160:	89 55 fc             	mov    %edx,-0x4(%rbp)		// rbp-4 = edx
    1163:	eb 09                	jmp    116e <func+0x25>		// 参数不等于零跳过以下代码
    1165:	b8 01 00 00 00       	mov    $0x1,%eax			// 参数等于0，跳转到此，eax = 1
    116a:	99                   	cltd						// 将%eax符号扩展到%edx，通常用来设置被除数
    116b:	f7 7d fc             	idivl  -0x4(%rbp)			// 余数存放在 %edx 寄存器, 商存放在 %eax 寄存器. 
    116e:	5d                   	pop    %rbp					// rbp=(rsp), rsp+8 ===> movq (%rsp),%rbp, addq $8, %rsp
    116f:	c3                   	retq						// ===> pop %rip

0000000000001170 <main>:
    1170:	f3 0f 1e fa          	endbr64 
    1174:	55                   	push   %rbp					// rsp=rsp-8, (rsp)=rbp ===> subq $8,%rsp, movq %rbp,(%rsp)
    1175:	48 89 e5             	mov    %rsp,%rbp			// rbp=rsp
    1178:	bf 05 00 00 00       	mov    $0x5,%edi			// edi = 5
    117d:	e8 c7 ff ff ff       	callq  1149 <func>			// func(edi)
    1182:	89 c6                	mov    %eax,%esi			// esi = eax = return value
    1184:	48 8d 3d 79 0e 00 00 	lea    0xe79(%rip),%rdi        # 2004 <_IO_stdin_used+0x4> 118b + 0xe79 = 2004
    118b:	b8 00 00 00 00       	mov    $0x0,%eax			// eax = 0
    1190:	e8 bb fe ff ff       	callq  1050 <printf@plt>	// printf(rdi,esi)
    1195:	90                   	nop
    1196:	5d                   	pop    %rbp					// rbp=(rsp), rsp+8 ===> movq (%rsp),%rbp, addq $8,%rsp
    1197:	c3                   	retq						// ===> pop %rip
    1198:	0f 1f 84 00 00 00 00 	nopl   0x0(%rax,%rax,1)		// 流水线指令优化
    119f:	00 

/*
 * arm
 */
000000000040055c <func>:
  40055c:	d10043ff 	sub	sp, sp, #0x10			// sp = sp-0x10
  400560:	b9000fe0 	str	w0, [sp, #12]			// sp+12 = w0 = parameter 1
  400564:	b9400fe0 	ldr	w0, [sp, #12]			// w0 = sp+12
  400568:	7100001f 	cmp	w0, #0x0				// parameter1 - 0x0
  40056c:	540000a0 	b.eq	400580 <func+0x24>  // b.none 参数等于零跳转
  400570:	b9400fe0 	ldr	w0, [sp, #12]			// 参数不等于零继续执行， w0 = parameter1
  400574:	11000401 	add	w1, w0, #0x1			// w1 = parameter1 + 1
  400578:	b9000fe1 	str	w1, [sp, #12]			// sp+12 = w1
  40057c:	14000004 	b	40058c <func+0x30>		// 跳到函数恢复堆栈处
  400580:	52800021 	mov	w1, #0x1                // #1, 参数等于0，跳转到此，w1 = 1
  400584:	b9400fe0 	ldr	w0, [sp, #12]			// parameter1
  400588:	1ac00c20 	sdiv	w0, w1, w0			// w0 = 1/parameter1, 有符号除法
  40058c:	910043ff 	add	sp, sp, #0x10			// 恢复堆栈
  400590:	d65f03c0 	ret							// w0是返回值，所以++后值没有变

0000000000400594 <main>:
  400594:	a9bf7bfd 	stp	x29, x30, [sp, #-16]!	// sp=sp-16, sp=x29, sp+8=x30
  400598:	910003fd 	mov	x29, sp					// x29=fp=sp
  40059c:	528000a0 	mov	w0, #0x5                   	// #5
  4005a0:	97ffffef 	bl	40055c <func>			// func(5)
  4005a4:	2a0003e1 	mov	w1, w0					// w1 = return value
  4005a8:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  4005ac:	9119c000 	add	x0, x0, #0x670			// x0 = "%d\n" address
  4005b0:	97ffffa8 	bl	400450 <printf@plt>		// printf(x0, w1)
  4005b4:	d503201f 	nop
  4005b8:	a8c17bfd 	ldp	x29, x30, [sp], #16		// x29=fp=sp, x30=lr=sp+8, sp=sp+16
  4005bc:	d65f03c0 	ret

#endif
